package com.gtenacg.cartoonservice.controller;

import com.gtenacg.cartoonservice.common.annotation.CheckToken;
import com.gtenacg.cartoonservice.common.Result;
import com.gtenacg.cartoonservice.pojo.model.RelationNovelType;
import com.gtenacg.cartoonservice.service.RelationNovelTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/relationNovelType")
@RequiredArgsConstructor
@CheckToken
public class RelationNovelTypeController {

    final RelationNovelTypeService relationNovelTypeService;

    @GetMapping
    public Result<List<RelationNovelType>> search(
            @RequestParam(required = false) Integer nid,
            @RequestParam(required = false) Integer ntid
    ) {
        log.info("获取对应列表（电子书-类型）, nid:{},ntid:{}", nid, ntid);
        List<RelationNovelType> list = relationNovelTypeService.search(nid, ntid);
        return Result.success(list);
    }

    @GetMapping("/list")
    public Result<List<RelationNovelType>> list() {
        log.info("获取对应列表（电子书-类型）");
        List<RelationNovelType> list = relationNovelTypeService.list();
        return Result.success(list);
    }

    @PostMapping
    public Result<Integer> insert(@RequestBody RelationNovelType relationNovelType) {
        log.info("新增对应（电子书-类型）: {}", relationNovelType);
        Integer id = relationNovelTypeService.insert(relationNovelType);
        return Result.success(id);
    }

    @PutMapping
    public Result<Void> update(@RequestBody RelationNovelType relationNovelType) {
        log.info("更新对应（电子书-类型）: {}", relationNovelType);
        relationNovelTypeService.update(relationNovelType);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result<Void> delete(@PathVariable List<Integer> ids) {
        log.info("删除对应（电子书-类型）: {}", ids);
        relationNovelTypeService.delete(ids);
        return Result.success();
    }

}
